/*
 * 利用JS对变量值进行加密
 * @params
 * content -- 需要加密的内容
 * */
document.write("<script language=javascript src='/static/public/aes/sha.js'></script>");
document.write("<script language=javascript src='/static/public/aes/aes.js'></script>");
var crypt_key = '59b6ab46d379b89d794c87b74a511fbd59b6ab46d379b89d794c87b74a511fbd';
//加密
function encrypt_js(content){
    var shaObj = new jsSHA("SHA-1", "TEXT");
    if(shaObj) {
        shaObj.update(crypt_key);
        var result = shaObj.getHash("HEX");
        result = result.toLocaleUpperCase();
        result = result.substr(0, 32);
    //    console.log(result);
        var key = crypt_key;//result;
        var iv = '0aaff094b6dc29742cc98a4bac8bc8f9'; //result;
        /*var key = CryptoJS.enc.Latin1.parse(result);
         var iv = CryptoJS.enc.Latin1.parse(result);*/
        var encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(content), CryptoJS.enc.Hex.parse(key), { iv: CryptoJS.enc.Hex.parse(iv) });

        return encrypted.ciphertext.toString();
    }
    return null;
}
//解密
function decrypt_js(content){
    var shaObj = new jsSHA("SHA-1", "TEXT");
    if(shaObj) {
        shaObj.update(crypt_key);
        var result = shaObj.getHash("HEX");
        result = result.toLocaleUpperCase();
        result = result.substr(0, 32);
        var key = crypt_key;//result;//CryptoJS.enc.Latin1.parse(result);
        var iv = '0aaff094b6dc29742cc98a4bac8bc8f9'; //result;//CryptoJS.enc.Latin1.parse(result);
        var cipherParams = CryptoJS.lib.CipherParams.create({ciphertext: CryptoJS.enc.Hex.parse(content)});
        var decrypted = CryptoJS.AES.decrypt(cipherParams, CryptoJS.enc.Hex.parse(key), { iv: CryptoJS.enc.Hex.parse(iv) });
        return decrypted.toString(CryptoJS.enc.Utf8);
    }
    return null;
}